import Vue from "vue";
import VueRouter from "vue-router";

//路由懒加载
let Login = () => import("../views/Login"); // 登录组件 ../views/login/index.vue 文件名是index的话可以省略
let Reg = () => import("../views/Reg"); //注册组件
let Layout = () => import("../views/Layout"); //主界面
let Users = () => import("../views/Users"); //用户管理
let Goods = () => import("../views/Goods"); //商品管理
let Orders = () => import("../views/Orders"); //订单管理
let Comments = () => import("../views/Comments"); //评论管理

Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "login",
    component: Login,
    //  meta是元信息，可利用设置路由守卫
    meta: {
      ischeck: false, //不需要路由守卫；
    },
  },
  {
    path: "/reg",
    name: "reg",
    component: Reg,
    meta: {
      ischeck: false,
    },
  },
  {
    path: "/",
    redirect: "/home", //重定向,后面会有路由拦截
  },
  {
    path: "/home",
    name: "home",
    component: Layout,
    children: [
      {
        path: "user",
        component: Users,
      },
      {
        path: "/home",
        redirect: "/home/user", //重定向
      },
      {
        path: "goods",
        component: Goods,
      },
      {
        path: "order",
        component: Orders,
      },
      {
        path: "comment",
        component: Comments,
      },
    ],
  },
];

const router = new VueRouter({
  mode : 'history',//history 模式路径就没有#号
  routes,
});

export default router;
